import { Menus } from '@/types/menu';

export const menuData: Menus[] = [
    {
        id: 'xtsy_0',
        title: '系统首页',
        index: '/dashboard',
        icon: 'Odometer',
    },
    {
        id: 'yxgl_0',
        title: '游戏管理',
        index: '1',
        icon: 'SwitchFilled',
        children: [
            {
                id: 'zbgl_1',
                index: '/pages/equipment',
                title: '装备管理',
            }
        ],
    },
    {
        id: 'xtgl_0',
        title: '系统管理',
        index: '2',
        icon: 'HomeFilled',
        children: [
            {
                id: 'jsgl_1',
                index: '/pages/role',
                title: '角色管理',
            },
            {
                id: 'icon_1',
                index: '/pages/icon',
                title: '图标管理',
            }
        ],
    },
    {
        id: 'zzgl_0',
        title: '组织管理',
        index: '3',
        icon: 'UserFilled',
        children: [
            {
                id: 'yhgl_1',
                index: '/pages/user',
                title: '用户管理',
            }
        ],
    },
    {
        id: 'zt_0',
        icon: 'Brush',
        index: '/theme',
        title: '主题',
    },
    {
        id: 'test_0',
        icon: 'Brush',
        index: '/test01',
        title: '测试界面',
    },
];
export function getMenuItemsByIds(ids: string[]): Menus[] {
    const result: Menus[] = [];

    function findMenuItemsByIds(menuItems: Menus[], ids: string[]): Menus[] {
        const filteredItems: Menus[] = [];
        for (const item of menuItems) {
            if (ids.includes(item.id)) {
                const menuItem = { ...item };
                if (menuItem.children) {
                    // 递归调用并赋值给menuItem.children
                    menuItem.children = findMenuItemsByIds(menuItem.children, ids);
                }
                filteredItems.push(menuItem);
            } else if (item.children) {
                // 过滤子菜单并更新当前菜单的children属性
                const filteredChildren = findMenuItemsByIds(item.children, ids);
                if (filteredChildren.length > 0) {
                    filteredItems.push({ ...item, children: filteredChildren });
                }
            }
        }
        return filteredItems; // 返回过滤后的菜单项
    }

    findMenuItemsByIds(menuData, ids).forEach(item => result.push(item));
    return result;
}
